# Maintainer: Steven Guikal <void@fluix.one>
pkgname=imv
pkgver=4.4.0
pkgrel=4
pkgdesc="Image viewer for X11/Wayland"
url="https://sr.ht/~exec64/imv"
arch="all !s390x" # freeimage-dev
license="MIT"
makedepends="
	asciidoc
	fontconfig-dev
	freeimage-dev
	glu-dev
	inih-dev
	libheif-dev
	libxkbcommon-dev
	mesa-dev
	meson
	pango-dev
	sdl2_ttf-dev
	wayland-dev
	"
checkdepends="
	cmocka
	cmocka-dev
	"
subpackages="$pkgname-doc $pkgname-wayland $pkgname-x11"
source="$pkgname-$pkgver.tar.gz::https://git.sr.ht/~exec64/imv/archive/v$pkgver.tar.gz
	move-wayland-and-x11-to-libexec.patch
	version.patch
	"
builddir="$srcdir/$pkgname-v$pkgver"

case $CARCH in
	s390x|riscv64)
		_rsvg=""
		;;
	*)
		makedepends="$makedepends librsvg-dev"
		_rsvg="-Dlibrsvg=enabled"
		;;
esac

build() {
	local _test=enabled
	if ! want_check; then
		_test=disabled
	fi
	abuild-meson \
		-Dwindows=all \
		-Dtest=$_test \
		-Dman=enabled \
		-Dfreeimage=enabled \
		-Dlibtiff=disabled \
		-Dlibpng=disabled \
		-Dlibjpeg=disabled \
		-Dlibnsgif=disabled \
		$_rsvg \
		. output
	meson compile -C output
}

check() {
	meson test --no-rebuild --print-errorlogs -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output
}

wayland() {
	pkgdesc="Image viewer for Wayland"
	depends="$pkgname=$pkgver-r$pkgrel"
	install_if="$pkgname=$pkgver-r$pkgrel wayland-libs-server"

	amove usr/libexec/imv-wayland
}

x11() {
	pkgdesc="Image viewer for X11"
	depends="$pkgname=$pkgver-r$pkgrel"
	install_if="$pkgname=$pkgver-r$pkgrel xorg-server"

	amove usr/libexec/imv-x11
}

sha512sums="
ddc0740022183a5467a0815ca623d2204b26449fee14b00c3468d06dbba3b5c3314b04a582bbac6075205f8d58cc24f157e283ce1ce3d34ecf0a9bdc497ab7f1  imv-4.4.0.tar.gz
e14260a79083393a5e81933adafe654892d6fc9e33f18eb906e9bcccc4227a9862851e234a0f14b457e87b8a9a7de71168d8b4fa18677b83105ab24bf3dcc60f  move-wayland-and-x11-to-libexec.patch
910880051a25d3dfe6a9dd6fc1db620f09e5bdcef90fff17509d3fc8252cbde3797c52848857d6dbfc47c4231a8152e55bd87bec846dbbdc9e9429091c27fb5c  version.patch
"
